package com.tenebrous.jestic.mapper.idao.framwork.system;

import com.tenebrous.jestic.entity.framwork.system.MetaDistrict;
import com.tenebrous.jestic.mapper.ISuperMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

//@Mapper
public interface MetaDistrictMapper extends ISuperMapper<MetaDistrict> {

    @Select("SELECT A.* FROM META_DISTRICT A WHERE A.DSTATE=1 ORDER BY A.LEVECODE,A.CODE")
    List<MetaDistrict> selectAll();

    @Select("SELECT A.*, (SELECT COUNT(*) FROM META_DISTRICT B WHERE B.PID=A.ID AND B.DSTATE=1) AS count_children FROM META_DISTRICT A WHERE A.PID=#{pid} AND A.DSTATE=1 ORDER BY A.LEVECODE,A.CODE")
    List<MetaDistrict> selectByPid(@Param("pid") String pid);

    @Select("SELECT A.* FROM META_DISTRICT A WHERE A.CODE=#{code}")
    MetaDistrict selectOneByCode(@Param("code") String code);

    @Select("SELECT A.*, (SELECT COUNT(*) FROM META_DISTRICT B WHERE B.PID=A.ID AND B.DSTATE=1) AS count_children FROM META_DISTRICT A WHERE A.ID=#{id}")
    MetaDistrict selectOneById(@Param("id") String id);

}